package basic.study.wantOffer.chapter5;

/**
 * @ClassName Problem46
 * @Description 把数字翻译成字符串
 * @Company inspur
 * @Author Kevin
 * @Date 2020/6/4 16:58
 * @Version 1.0
 */
public class Problem46 {
    static class TranslateNumbersToStrings {
        public int getTranslationCount(int number) {
            if (number < 0) {
                return 0;
            }
            String sNumber = String.valueOf(number);
            int[] count = new int[sNumber.length()];

            for (int i = sNumber.length() -1; i >= 0; i--) {
                if (i == sNumber.length() -1) {
                    count[i] = 1;
                } else {
                    count[i] = count[i+1];
                    if (canTransfer(sNumber, i)) {
                        if (i == sNumber.length() -2) {
                            count[i] += 1;
                        } else {
                            count[i] += count[i+2];
                        }
                    }
                }
            }

            return count[0];
        }

        private boolean canTransfer(String sNumber, int i) {
            int a = sNumber.charAt(i) - '0';
            int b = sNumber.charAt(i+1) - '0';
            int num = 10 * a + b;
            if (10 <= num && num <= 25) {
                return true;
            } else {
                return false;
            }
        }
    }

    public static void main(String[] args) {
        TranslateNumbersToStrings tans = new TranslateNumbersToStrings();
        System.out.println(tans.getTranslationCount(0));//1
        System.out.println(tans.getTranslationCount(10));//2
        System.out.println(tans.getTranslationCount(12258));//5
        System.out.println(tans.getTranslationCount(-100));//0
    }
}
